use calamine::{open_workbook, Error, RangeDeserializerBuilder, Reader, Xlsx};

use serde::Deserialize;

#[derive(Deserialize, Debug, Clone, StructuralConvert)]
pub struct Model {
    pub combi_tool_info: Option<String>,
    pub mat_code: String,
    pub mat_name: Option<String>,
    pub mat_details: Option<String>,
    pub workshop: Option<String>,
    pub project_name: Option<String>,
    pub tool_type: Option<String>,
    pub sub_tool_type: Option<String>,
    pub tool_code: Option<String>,
    pub tool_name: Option<String>,
    pub tool_specs: Option<String>,
    pub tool_model: Option<String>,
    pub purchase_remarks: Option<String>,
    pub tool_model_recommended: Option<String>,
    pub tool_cps: Option<String>,
}

use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Error> {
    
    let path = "files/upload.xlsx";
    let mut workbook: Xlsx<_> = open_workbook(path)?;

    let range = workbook
        .worksheet_range("工刀量具物料编码件号对应关系")
        .or(Err(Error::Msg(
            "Cannot find '工刀量具物料编码件号对应关系'",
        )))?;

    let mut iter = RangeDeserializerBuilder::with_headers(&[
        "mat_code",
        "mat_name",
        "mat_details",
        "workshop",
        "tool_type",
        "project_name",
        "sub_tool_type",
        "tool_code",
        "tool_name",
        "tool_specs",
        "tool_model",
        "purchase_remarks",
        "tool_model_recommended",
        "tool_cps",
    ])
    .from_range(&range)?;

    while let Some(result) = iter.next() {}

    Ok(())
}
